Table
The Table Module for the computer API!
Functions
merge
sm.scrapcomputers.table.merge( tbl1, tbl2, fullOverwrite )
Merges 2 tables in 1.
The order that you put the sm.scrapcomputers.table.merge matters! tbl2
will override/overwrite anything inside tbl1
!
Arguments:
- tbl1 [ table ] The 1st table
- tbl2 [ table ] The 2nd table
- fullOverwrite [ boolean? ] This will make it so the merged value will be always from tbl2. Will not care about anything else. The default is
false
Returns:
- tbl [ table ] The merged table.
clone
sm.scrapcomputers.table.clone( tbl )
Clones a table
This function doesn't really need to exist
This function is utterly unnecessary but in SOME situations is useful. It does create a new table but it's so easy to implement that I don't think it should deserve to have its function.
Guess why
Click this dropdown to see why its unnessorary
This is all the code the function uses...
---Clones a table
---@param tbl table The table to clone
---@return table clonedTable The cloned table
sm.scrapcomputers.table.clone = function (tbl)
assert(type(tbl) == "table", "Expected table, got "..type(tbl).." instead.") -- Отслеживание ошибки
return unpack({tbl})
end
It's too little amount of code! I could do it in different ways but those have downsides! So this is the easiest thing we can do.
Arguments:
- tbl [ table ] The table to clone.
Returns:
- [ table ] The cloned table.
toString
sm.scrapcomputers.table.toString( tbl )
Converts a table to the same thing but as a string. If you were to try doing this with Lua's tostring. You would just get "table: 00A59928". Not the actual contents of the table itself!
Arguments:
- tbl [ table ] The table.
Returns:
- [ string ] The converted lua table is a string.
getItemAt
sm.scrapcomputers.table.getItemAt( tbl, index )
Gets an item from a table via the index. Unlike doing tbl[index]
. This will not care if the index numbers aren't in order.
-- This is in our actual todo
local todo = {
[25] = "Add glass support for camera"
[69] = "Add another parameter for speakers. Allows you to add such as the \"wind\" parameter to the sound effect"
[4825] = "Add 512x512 and 1024x1024 displays for 3x3, 2x2 and 1x1 (Im going to add this no matter what :) )"
}
local lastTodoGood = sm.scrapcomputers.table.getItemAt(todo, 3) -- Works! Returns item of the index of 4825. Since it's the 3rd element in the table
local lastTodoBad = todo[3] -- Doesn't Work! Tries grabbing an element at index 3 but that doesn't exist! so this is nil!
print("lastTodoGood: "..tostring(lastTodoGood))
print("lastTodoBad: " ..tostring(lastTodoBad ))
You see that tbl[index] would error out but not sm.scrapcomputers.table.getItemAt
Arguments:
- tbl [ table ] The table
- index [ integer ] The item to get.
Returns:
- [ any ] Whatever data it has received from the index.
getTableSize
sm.scrapcomputers.table.getTableSize( tbl )
Gets all items via a ipairs loop.
Unlike doing #tbl, If the indexing was weird, #tbl would return 0. This function does not care if the indexing system is weird. Will give you the same result as if the indexing system was normal.
Arguments:
- tbl [ table ] The table.
Returns:
- [ integer ] The total items in the table.
shiftTableIndexes
sm.scrapcomputers.table.shiftTableIndexes( tbl, shiftAmount )
Shifts list's indexes.
Arguments:
- tbl [ table ] table The table.
- shiftAmount [ integer ] integer The amount to shift.
Returns:
- [ table ] The shifted table.
isDictionary
sm.scrapcomputers.table.isDictionary( tbl )
Returns true if your table is a dictionary.
Arguments:
- tbl [ table ] The table.
Returns:
- [ boolean ] Whether your table is a dictionary or not.
numberlyOrderTable
sm.scrapcomputers.table.numberlyOrderTable( tbl )
Orders the list to be 1 to table size.
Arguments:
- tbl [ table ] The table to check.
Returns:
- [ table ] The organized table.
valueExistsInList
sm.scrapcomputers.table.valueExistsInList( tbl, item )
Returns true if an item is found in a list.
Arguments:
- tbl [ table ] The table to check.
- item [ any ] The item to try finding the table. (Cannot be nil!).
Returns:
- [ boolean ] If it was found or not.